package com.solcoo.dao;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.solcoo.json.DownloadToExcelByYongHuJson;
import com.solcoo.json.ShanghuDataJson;
import com.solcoo.json.ShanghuSimpleJson;

@Repository
public class DataDao {

	@Resource
	private SqlMapClient sqlMapClient;
	 
	/**
	 * 获取年实收款总数
	 */
	public Double getTotalSskByYear(String year, Long yonghum) throws SQLException {
		Map<String, Object> param = new HashMap<String, Object>();
		
		param.put("year", year);
		param.put("yonghum", yonghum);
		
		return (Double) sqlMapClient.queryForObject("getTotalSskByYear", param);
	}
	
	/**
	 * 获取月实收款总数
	 */
	public Double getSskByYearAndMonth(String yearAndMonth, Long yonghum) throws SQLException {
		Map<String, Object> param = new HashMap<String, Object>();
		
		param.put("yearAndMonth", yearAndMonth);
		param.put("yonghum", yonghum);
		
		return (Double) sqlMapClient.queryForObject("getSskByYearAndMonth", param);
	}
	
	/**
	 * 获取年会员总数
	 */
	public Integer getTotalVipCountByYear(Map<String, Object> param) throws SQLException {
		return (Integer) sqlMapClient.queryForObject("getTotalVipCountByYear", param);
	}
	
	/**
	 * 获取年用户总数
	 */
	public Integer getTotalYongHuCountByYear(Map<String, Object> param) throws SQLException {
		return (Integer) sqlMapClient.queryForObject("getTotalYongHuCountByYear", param);
	}
	
	/**
	 * 获取年商户总数
	 */
	public Integer getTotalShangHuCountByYear(String year) throws SQLException {
		return (Integer) sqlMapClient.queryForObject("getTotalShangHuCountByYear", year);
	}
	
	/**
	 * 获取月会员总数
	 */
	public Integer getVipCountByYearAndMonth(String yearAndMonth, Long yonghum) throws SQLException {
		String[] ss = yearAndMonth.split("-");
		
		Map<String, Object> param = new HashMap<String, Object>();
		
		param.put("year", ss[0]);
		param.put("month", ss[1]);
		param.put("yonghum", yonghum);
		
		return (Integer) sqlMapClient.queryForObject("getVipCountByYearAndMonth", param);
	}
	
	/**
	 * 获取月用户总数
	 */
	public Integer getYongHuCountByYearAndMonth(String yearAndMonth) throws SQLException {
		String[] ss = yearAndMonth.split("-");
		
		Map<String, Object> param = new HashMap<String, Object>();
		
		param.put("yearAndMonth", yearAndMonth);
		
		return (Integer) sqlMapClient.queryForObject("getYongHuCountByYearAndMonth", param);
	}
	
	/**
	 * 获取月交易笔数
	 */
	public Integer getBusinessCountByYearAndMonth(String yearAndMonth, Long yonghum) throws SQLException {
		Map<String, Object> param = new HashMap<String, Object>();
		
		param.put("yearAndMonth", yearAndMonth);
		param.put("yonghum", yonghum);
		
		return (Integer) sqlMapClient.queryForObject("getBusinessCountByYearAndMonth", param);
	}
	
	/**
	 * 获取商户数量
	 */
	public Integer getMerchantCountByYearAndMonth(String yearAndMonth) throws SQLException {
		return (Integer) sqlMapClient.queryForObject("getMerchantCountByYearAndMonth", yearAndMonth);
	}
	
	/**
	 * 获取主账户交易次数
	 */
	public Integer getZhuYonghuJYCount(String yearAndMonth, Long yonghum) throws SQLException {
		Map<String, Object> param = new HashMap<String, Object>();
		
		param.put("yearAndMonth", yearAndMonth);
		param.put("yonghum", yonghum);
		
		return (Integer) sqlMapClient.queryForObject("getZhuYonghuJYCount", param);
	}
	
	/**
	 * 获取子帐号交易次数
	 */
	public Integer getZhiYonghuJYCount(String yearAndMonth, Long yonghum) throws SQLException {
		Map<String, Object> param = new HashMap<String, Object>();
		
		param.put("yearAndMonth", yearAndMonth);
		param.put("yonghum", yonghum);
		
		return (Integer) sqlMapClient.queryForObject("getZhiYonghuJYCount", param);
	}
	
	/**
	 * 获取主账户撤销次数
	 */
	public Integer getZhuYonghuCXCount(String yearAndMonth, Long yonghum) throws SQLException {
		Map<String, Object> param = new HashMap<String, Object>();
		
		param.put("yearAndMonth", yearAndMonth);
		param.put("yonghum", yonghum);
		
		return (Integer) sqlMapClient.queryForObject("getZhuYonghuCXCount", param);
	}
	
	/**
	 * 获取子帐号撤销次数
	 */
	public Integer getZhiYonghuCXCount(String yearAndMonth, Long yonghum) throws SQLException {
		Map<String, Object> param = new HashMap<String, Object>();
		
		param.put("yearAndMonth", yearAndMonth);
		param.put("yonghum", yonghum);
		
		return (Integer) sqlMapClient.queryForObject("getZhiYonghuCXCount", param);
	}
	
	/**
	 * 获取首次关注数量
	 */
	public Integer getShouciGZCount(String yearAndMonth, Long yonghum) throws SQLException {
		Map<String, Object> param = new HashMap<String, Object>();
		
		param.put("yearAndMonth", yearAndMonth);
		param.put("yonghum", yonghum);
		
		return (Integer) sqlMapClient.queryForObject("getShouciGZCount", param);
	}
	
	/**
	 * 获取商户数据
	 */
	public List<ShanghuDataJson> getShanghuData() throws SQLException {
		return sqlMapClient.queryForList("getShanghuData");
	}
	
	/**
	 * 获取简单的商户信息
	 */
	public List<ShanghuSimpleJson> getShanghuSimple() throws SQLException {
		return sqlMapClient.queryForList("getShanghuSimple", new HashMap<String, Object>());
	}
	
	/**
	 * 获取商户名称
	 */
	public String getShanghumcByYonghum(Long yonghum) throws SQLException {
		return (String) sqlMapClient.queryForObject("getShanghumcByYonghum", yonghum);
	}

	/**
	 * 获取商户月新增会员数量数组
	 */
	public Integer getAddVipsByShanghu(String yearAndMonth, Long yonghum) throws SQLException {
		Map<String, Object> param = new HashMap<String, Object>();
		
		param.put("yearAndMonth", yearAndMonth);
		param.put("yonghum", yonghum);
		
		return (Integer) sqlMapClient.queryForObject("getAddVipsByShanghu", param);
	}
	
	/**
	 * 获取日新增用户数量
	 */
	public Integer getYongHuCountsByDay(String ymd) throws SQLException {
		return (Integer) sqlMapClient.queryForObject("getYongHuCountsByDay", ymd);
	}

	/**
	 * 获取日实收款
	 */
	public Double getSsksByDay(String ymd, Long yonghum) throws SQLException {
		Map<String, Object> param = new HashMap<String, Object>();
		
		param.put("ymd", ymd);
		param.put("yonghum", yonghum);
		
		return (Double) sqlMapClient.queryForObject("getSsksByDay", param);
	}
	
	/**
	 * 获取日新增会员数量
	 */
	public Integer getVIPCountsByDay(String ymd, Integer yonghum) throws SQLException {
		Map<String, Object> param = new HashMap<String, Object>();
		
		param.put("ymd", ymd);
		param.put("yonghum", yonghum);
		
		return (Integer) sqlMapClient.queryForObject("getVIPCountsByDay", param);
	}
	
	/**
	 * 获取用户使用情况
	 */
	public List<DownloadToExcelByYongHuJson> getYongHuSYQK() throws SQLException {
		return sqlMapClient.queryForList("getYongHuSYQK", new HashMap<String, Object>());
	}
	
}